<template>
	<view>
		<scroll-view class="mycss-scroll-view-H" scroll-x="true">
			<view class="mycss-flex-start">
				<slot name="foucs"></slot>
				<view class="uni-ma-3">
					<u-button :type="showCols?'primary':'warning'" :customStyle="{padding:'0px'}" size="small"
						@click="showTimeCols()">{{showCols?'隐藏首列':'显示首列'}}</u-button>
				</view>
				<view class="mycss-flex-start uni-mt-3">
					<u-button text="前一天" size="small" :customStyle="{padding:'0px'}" type="primary"
						@click="changeDay('preDay')"></u-button>
					<u-button :text="lookDay" size="small" :type="lookDay==today?'warning':'primary'" :plain="true"
						@click="changeDay('nowDay')"></u-button>
					<u-button text="后一天" size="small" type="primary" :customStyle="{padding:'0px'}"
						@click="changeDay('nextDay')"></u-button>
				</view>

				<view class="uni-ma-3">
					<uni-pagination show-icon="true" :total="total" :current="params.page" :pageSize="params.size"
						@change="doChangePage"></uni-pagination>
				</view>
				<view class="uni-ma-3">
					<u-button type="primary" size="small" @click="showCalendar=true">日期选择</u-button>
				</view>
			</view>
		</scroll-view>
		<view class="mycss-flex-start">
			<view style="width:280rpx" v-if="showCols">
				<uni-table border stripe>
					<uni-tr>
						<uni-th align="center">
							<view>
								时间段-日期
							</view>
						</uni-th>
					</uni-tr>
					<uni-tr v-for="item in tdata.morningTimeList" :key="item.endTime">
						<uni-td align="center">
							<view>
								{{ item.startTime }}-{{ item.endTime }}
							</view>
						</uni-td>
					</uni-tr>
					<uni-tr>
						<uni-td align="center">
							<view class="noback">
								下班
							</view>
						</uni-td>
					</uni-tr>
					<uni-tr v-for="item in tdata.afternoonTimeList" :key="item.endTime">
						<uni-td align="center">
							<view>
								{{ item.startTime }}-{{ item.endTime }}
							</view>
						</uni-td>
					</uni-tr>
					<uni-tr>
						<uni-td align="center">
							<view class="noback">
								下班
							</view>
						</uni-td>
					</uni-tr>
					<uni-tr v-for="item in tdata.nightTimeList" :key="item.endTime">
						<uni-td align="center">
							<view @click="toggle('bottom')">
								{{ item.startTime }}-{{ item.endTime }}
							</view>
						</uni-td>
					</uni-tr>
				</uni-table>
			</view>
			<scroll-view :class="{'my-scroll-view-H':showCols,'mycss-scroll-view-H':showCols}" scroll-x="true">
				<checkbox-group @change="checkboxChange">
					<uni-table border stripe>
						<uni-tr>
							<uni-th align="center" v-for="(item,index) in tableData" :key="index">
								<text @click="goPersonalPlan(tableData2,item,index)" style="white-space: nowrap;">
									{{item.name}}
								</text>
							</uni-th>
						</uni-tr>
						<uni-tr v-for="item in tdata.morningTimeList" :key="item.endTime">
							<uni-td align="center" v-for="(obj,index) in tableData" :key="index">
								<view class="mycss-flex-start" :class="getItemForClass(obj,item,'c')">
									<checkbox :value="getCheckBoxName(obj,item)" v-if="getItem(obj,item)?true:false"
										color="#FFCC33" style="transform:scale(0.7)"
										:checked="clickItems.includes(getCheckBoxName(obj,item))" />
									<view :class="getItemForClass(obj,item)"
										@click="toggle('bottom',obj,item,getItem(obj,item)?'edit':'new')">
										<view class="mycontent">
											{{getItem(obj,item)?getItem(obj,item).content:"&nbsp;"}}
										</view>
										<uni-badge class="uni-badge-left-margin bfloat"
											v-if="getItem(obj,item)?getItem(obj,item).state==1:false" text="完成"
											:customStyle="{background: '#5fd652'}" />
									</view>
								</view>
							</uni-td>
						</uni-tr>
						<uni-tr>
							<uni-td align="center" v-for="item in tableData" :key="item.id">
								<view class="noback">
									&nbsp;
								</view>
							</uni-td>
						</uni-tr>
						<uni-tr v-for="item in tdata.afternoonTimeList" :key="item.endTime">
							<uni-td align="center" v-for="(obj,index) in tableData" :key="index">
								<view class="mycss-flex-start" :class="getItemForClass(obj,item,'c')">
									<checkbox :value="getCheckBoxName(obj,item)" v-if="getItem(obj,item)?true:false"
										color="#FFCC33" style="transform:scale(0.7)"
										:checked="clickItems.includes(getCheckBoxName(obj,item))" />
									<view :class="getItemForClass(obj,item)"
										@click="toggle('bottom',obj,item,getItem(obj,item)?'edit':'new')">
										<view class="mycontent">
											{{getItem(obj,item)?getItem(obj,item).content:"&nbsp;"}}
										</view>
										<uni-badge class="uni-badge-left-margin bfloat"
											v-if="getItem(obj,item)?getItem(obj,item).state==1:false" text="完成"
											:customStyle="{background: '#5fd652'}" />
									</view>
								</view>
							</uni-td>
						</uni-tr>
						<uni-tr>
							<uni-td align="center" v-for="item in tableData" :key="item.id">
								<view class="noback">
									&nbsp;
								</view>
							</uni-td>
						</uni-tr>
						<uni-tr v-for="item in tdata.nightTimeList" :key="item.endTime">
							<uni-td align="center" v-for="(obj,index) in tableData" :key="index">
								<view class="mycss-flex-start" :class="getItemForClass(obj,item,'c')">
									<checkbox :value="getCheckBoxName(obj,item)" v-if="getItem(obj,item)?true:false"
										color="#FFCC33" style="transform:scale(0.7)"
										:checked="clickItems.includes(getCheckBoxName(obj,item))" />
									<view :class="getItemForClass(obj,item)"
										@click="toggle('bottom',obj,item,getItem(obj,item)?'edit':'new')">
										<view class="mycontent">
											{{getItem(obj,item)?getItem(obj,item).content:"&nbsp;"}}
										</view>
										<uni-badge class="uni-badge-left-margin bfloat"
											v-if="getItem(obj,item)?getItem(obj,item).state==1:false" text="完成"
											:customStyle="{background: '#5fd652'}" />
									</view>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
				</checkbox-group>
			</scroll-view>
		</view>
		<view>
			<uni-popup ref="popup" background-color="#fff">
				<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
					<scroll-view scroll-y="true" class="mycss-max-height85">
						<uni-row>
							<uni-col>
								<view class="mycss-flex-around mycss-title-bg">
									<view class="uni-ma-5">
										<text>{{openTitle}}</text>
									</view>
								</view>
							</uni-col>
						</uni-row>
						<uni-card title="日期" v-if="isEdit==false&&isMulti==false">
							<view class="mycss-flex-start-clumncenter-warp">
								<button type="primary" :disabled="true" size="mini" class="uni-ma-2"
									style="padding:0px 10px;">{{lookDay}}</button>
							</view>
						</uni-card>
						<uni-card title="上午" v-if="!isEdit">
							<view class="mycss-flex-start-clumncenter-warp">
								<button :type="getButtonType(todayUseTime,item,selectTimeList)"
									:disabled="todayUseTime.includes(item.startTime+'-'+item.endTime)?true:false"
									size="mini"
									:plain="todayUseTime.includes(item.startTime+'-'+item.endTime)||selectTimeList.includes(item.startTime+'-'+item.endTime)?false:true"
									class="uni-ma-2" style="padding:0px 10px;"
									v-for="(item,index) in tdata.morningTimeList" :key="index"
									@click="timeClick(item)">{{item.startTime}}-{{item.endTime}}</button>
							</view>
						</uni-card>
						<uni-card title="下午" v-if="!isEdit">
							<view class="mycss-flex-start-clumncenter-warp">
								<button :type="getButtonType(todayUseTime,item,selectTimeList)"
									:disabled="todayUseTime.includes(item.startTime+'-'+item.endTime)?true:false"
									size="mini"
									:plain="todayUseTime.includes(item.startTime+'-'+item.endTime)||selectTimeList.includes(item.startTime+'-'+item.endTime)?false:true"
									class="uni-ma-2" style="padding:0px 10px;"
									v-for="(item,index) in tdata.afternoonTimeList" :key="index"
									@click="timeClick(item)">{{item.startTime}}-{{item.endTime}}</button>
							</view>
						</uni-card>
						<uni-card title="晚上" v-if="!isEdit">
							<view class="mycss-flex-start-clumncenter-warp">
								<button :type="getButtonType(todayUseTime,item,selectTimeList)"
									:disabled="todayUseTime.includes(item.startTime+'-'+item.endTime)?true:false"
									size="mini"
									:plain="todayUseTime.includes(item.startTime+'-'+item.endTime)||selectTimeList.includes(item.startTime+'-'+item.endTime)?false:true"
									class="uni-ma-2" style="padding:0px 10px;"
									v-for="(item,index) in tdata.nightTimeList" :key="index"
									@click="timeClick(item)">{{item.startTime}}-{{item.endTime}}</button>
							</view>
						</uni-card>
						<uni-card title="时间段" v-if="isEdit&&isMulti==false">
							<view class="mycss-flex-start-clumncenter-warp">
								<button type="primary" disabled>{{editobj.startTime+"-"+editobj.endTime}}</button>
							</view>
						</uni-card>
						<uni-card title="类型(必须)">
							<view class="mycss-flex-start-clumncenter-warp">
								<u-radio-group v-model="typeDefault">
									<u-radio :customStyle="{margin: '5px'}" v-for="(item, index) in typeList"
										:key="index" :label="item.name" :name="item.id" @change="radioTypeChange">
									</u-radio>
								</u-radio-group>
								<!-- <u-switch v-model="ywShow" @change="switchChange"></u-switch> -->
							</view>
							<view v-if="projectShow">
								<u-tag text="没有可用的工程列表" type="warning" v-if="projectList.length==0">
								</u-tag>
								<u-radio-group v-model="projectClickData">
									<u-radio :customStyle="{margin: '5px'}" v-for="(item, index) in projectList"
										:key="index" :label="item.name" :name="item.id"
										@change="radioTypeChangeProject">
									</u-radio>
								</u-radio-group>
							</view>
							<view v-if="ywShow">
								<u-radio-group v-model="updownClickData">
									<u-radio :customStyle="{margin: '5px'}" v-for="(item, index) in updownList"
										:key="index" :label="item.label" :name="item.id"
										@change="radioTypeChangeUpdown">
									</u-radio>
								</u-radio-group>
								<uni-easyinput class="uni-mt-5" v-model="inputSearchYw" suffixIcon="search"
									placeholder="输入业务名称" @iconClick="searchYw"></uni-easyinput>
								<u-line color="#2979ff"></u-line>
								<u-radio-group v-model="displayAddrClickData">
									<u-radio :customStyle="{margin: '5px'}" v-for="(item, index) in dispAddrList"
										:key="index" :label="item.name" :name="item.id+'_'+item.name"
										@change="radioTypeChangeYwlist">
									</u-radio>
								</u-radio-group>
							</view>
						</uni-card>
						<uni-card title="标题(必须)">
							<view class="mycss-flex-start-clumncenter-warp">
								<u-tag :text="item.name" :bgColor="item.color" closable
									@close="deleteTag(item,'personal-title')" v-for="(item,index) in titleTags"
									:key="index" @click="clickTag(item.name,'title')">
								</u-tag>
							</view>
							<view class="mycss-flex-start-clumncenter-warp">
								<uni-icons type="compose" size="30" @click="openColorPick"
									:color="clickColor"></uni-icons>
								<uni-easyinput class="uni-mt-5" v-model="inputTitleText" suffixIcon="plus"
									placeholder="输入标题" @iconClick="addTag('personal-title')"></uni-easyinput>
							</view>
						</uni-card>
						<uni-card title="计划内容">
							<view class="mycss-flex-start-clumncenter-warp">
								<u-tag :text="item.name" :bgColor="item.color" closable
									@close="deleteTag(item,'personal-content')" v-for="(item,index) in contentTags"
									@click="clickTag(item.name,'content')" :key="index">
								</u-tag>
							</view>
							<view class="mycss-flex-start-clumncenter-warp">
								<uni-easyinput class="uni-mt-5" v-model="inputContentText" suffixIcon="plus"
									placeholder="输入内容" @iconClick="addTag('personal-content')"></uni-easyinput>
							</view>
						</uni-card>
					</scroll-view>
					<uni-row>
						<uni-col>
							<view class="mycss-flex-end">
								<view class="uni-ma-3">
									<button type="primary" size="mini" @click="planSave()">保存</button>
								</view>
								<view class="uni-ma-3">
									<button type="warn" size="mini" @click="planClose">关闭</button>
								</view>
							</view>
						</uni-col>
					</uni-row>
				</view>
			</uni-popup>
		</view>
		<TColorPicker ref="colorPicker" @confirm="confirmColor"></TColorPicker>
		<u-datetime-picker :show="showCalendar" v-model="selectDate" mode="date" closeOnClickOverlay
			@confirm="confirmDate" @cancel="cancelDate"></u-datetime-picker>
		<u-toast ref="myuToast"></u-toast>
		<uni-fab v-if="clickItems.length>0&&clickItems[0]" ref="myfab" :pattern="fab.pattern" :content="fab.content"
			:horizontal="fab.horizontal" :vertical="fab.vertical" :direction="fab.direction" @trigger="triggerfab" />
	</view>
</template>

<script setup>
	import tdata from "@/pages/personal-plan/components/tdata.js"
	import fab from '@/pages/personal-plan/components/fab.js'
	import TColorPicker from '@/components/t-color-picker/t-color-picker.vue'
	import MyLoading from "@/components/my-loading/my-loading"
	import {
		formatDate,
		parseDate
	} from "@/utils/dateUtil.js"
	import {//解构
		ref,
		reactive,
		inject,
		onMounted,
		watchEffect,
		watch
	} from "vue"
	import {
		onLoad,
		onReady
	} from "@dcloudio/uni-app"
	const http = inject("$http");
	const utils = inject("$utils");
	const pinia = inject("$pinia")
	const myfab = ref();//基本型
	const showCols = ref(true);
	const today = ref(formatDate(new Date(), "yyyy-MM-dd"));
	const lookDay = ref("");
	const tableData = reactive([])
	let tableData2 = [] //用来选上一位下一位的
	const departIds = ref("");
	const total = ref(0);
	const popup = ref();
	const myuToast = ref();
	const showCalendar = ref(false);
	//是不是多项编辑
	const isMulti = ref(false);
	const selectDate = ref("");
	const params = reactive({
		page: 1,
		size: 5
	});
	const tmap = new Map();
	const clickItems = reactive([]);
	const clickColor = ref("#8e8e8e"); //确认后的颜色
	const colorPicker = ref();
	//选择的时间list
	const selectTimeList = reactive([]);
	const selectDayList = reactive([]);
	const todayUseTime = reactive([]);
	const clickUserId = ref();

	//上下游list
	const updownList = reactive([]);
	//类型list前台写死
	const typeList = reactive([{
		"id": 0,
		"name": "日常事务"
	}, {
		"id": 1,
		"name": "项目事务"
	}, {
		"id": 3,
		"name": "额外事务"
	}, {
		"id": 4,
		"name": "请假"
	}, {
		"id": 5,
		"name": "业务专属"
	}]);
	const typeDefault = ref(0);
	//地点list
	const addrList = reactive([]);
	//用来显示的地址列表
	const dispAddrList = reactive([]);
	//标题的标签
	const titleTags = reactive([]);
	//内容的标签
	const contentTags = reactive([]);
	//是否是编辑
	const isEdit = ref(false);
	//editobj
	let editobj = {};
	//标题输入框
	const inputTitleText = ref("");
	//内容输入框
	const inputContentText = ref("");
	const projectList = reactive([]);
	const projectShow = ref(false);
	const ywShow = ref(false);
	//默认勾中项目
	const updownClickData = ref(3);
	const displayAddrClickData = ref()
	const projectClickData = ref()
	//弹出框title
	const openTitle = ref("个人计划新增")
	//定义组件参数
	const props = defineProps({
		url: {
			type: String,
			default: ""
		},
		groupId: {
			type: String,
			default: ""
		}
	});
	watch(
		() => props.groupId,
		(val, preVal) => {
			//val为修改后的值,preVal为修改前的值
			console.log("groupId", val, preVal)
			findData();
		}, {
			//如果加了这个参数，值为true的话，就消除了惰性，watch会在创建后立即执行一次
			//那么首次执行，val为默认值,preVal为undefined
			immediate: true,
			//这个参数代表监听对象时，可以监听深度嵌套的对象属性
			//比如message是一个对象的话，可以监听到message.a.b.c，也就是message下的所有属性
			deep: true,
		}
	)
	// watchEffect((onInvalidate)=>{
	// 	console.log(props.groupId,"pppppppppppppppppp");
	// 	//已经使用的时间
	// 	findData();
	// 	onInvalidate(() => {
	// 		//当组件失效，watchEffect被主动停止或者副作用即将重新执行时，这个函数会执行
	// 	})
	// })
	onMounted(() => {
		console.log(colorPicker.value);
		console.log(popup.value);
		console.log(myuToast.value)
		console.log(myfab.value)
	})
	onLoad(() => {
		console.log(props.groupId, "=====================");
		lookDay.value = today.value;
		findData();
		findAllData();
	})
	//弹出框
	function toggle(type, obj, item, opentype) {
		selectDayList.splice(0, selectDayList.length)
		selectTimeList.splice(0, selectTimeList.length)
		todayUseTime.splice(0, todayUseTime.length);
		ywShow.value = false;
		projectShow.value = false;
		clickUserId.value = obj.id;
		if ('new' == opentype) {
			openTitle.value = "个人计划新增"
			isMulti.value = false;
			isEdit.value = false;
		} else if ('edit' == opentype) {
			openTitle.value = "个人计划编辑"
			editobj = getItem(obj, item);
			typeDefault.value = editobj.type;
			inputTitleText.value = editobj.title;
			inputContentText.value = editobj.content;
			isEdit.value = true;
			if (1 == typeDefault.value) {
				projectShow.value = true;
			}
			if (5 == typeDefault.value) {
				ywShow.value = true;
			}
		}
		popup.value.open(type)
		if (opentype == 'new') {
			//已经使用的时间
			http.post("/personalPlan/getUsedTime", {
				workDate: lookDay.value,
				userId: obj.id
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					res.data.data.forEach((item) => {
						todayUseTime.push(item);
					});
					todayUseTime.unshift(item.startTime + "-" + item.endTime);
				}
			}).catch((re) => {
				console.log(re);
			});
		}
		//项目计划列表
		http.get("/projectPlan/getProjectPlansByUserId", {
			workDate: lookDay.value,
			userId: obj.id
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				res.data.data.forEach((item) => {
					projectList.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
		//标题标签
		http.post("/tag/query", {
			type: 'personal-title'
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				titleTags.splice(0, titleTags.length)
				res.data.data.forEach((item) => {
					titleTags.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
		//内容标签
		http.post("/tag/query", {
			type: 'personal-content'
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				contentTags.splice(0, titleTags.length)
				res.data.data.forEach((item) => {
					contentTags.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
		//上下游
		http.post("/typeDic/getUpDown").then((res) => {
			if (res && res.data && res.data.code == 1) {
				updownList.splice(0, updownList.length)
				res.data.data.forEach((item) => {
					updownList.push(item);
				});
				updownList.unshift({
					id: 3,
					label: "全部",
					value: 3
				})
			}
		}).catch((re) => {
			console.log(re);
		});
		//地点List
		http.post("/typeDic/table3", {
			keyWord: "person_plan_ywtype",
			page: 1,
			size: 10000
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				addrList.splice(0, addrList.length);
				dispAddrList.splice(0, dispAddrList.length);
				res.data.rows.forEach((item) => {
					addrList.push(item);
					dispAddrList.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
	}

	function showTimeCols() {
		showCols.value = !showCols.value;
	}

	function findAllData() {
		let paramall = {
			...params
		}
		paramall.workDate = lookDay.value;
		tableData2.splice(0, tableData2.length);
		http.post("/depart/indexDepart").then((res) => {
			if (res && res.data && res.data.code == 1) {
				departIds.value = res.data.idsStr;
			}
		}).then(() => {
			paramall.departIds = departIds.value;
			if (props.groupId != "") {
				paramall.groupId = props.groupId;
				delete paramall.departIds
			}
			paramall.size = 10000;
			http.post(props.url, paramall).then((res) => {
				if (res && res.data && res.data.code == 1) {
					res.data.rows.forEach((item) => {
						tableData2.push(item)
					});
				}
			}).catch((re) => {
				console.log(re);
			});
		}).catch((re) => {
			console.log(re);
		});
	}

	function findData() {
		params.workDate = lookDay.value;
		tableData.splice(0, tableData.length);
		http.post("/depart/indexDepart").then((res) => {
			if (res && res.data && res.data.code == 1) {
				departIds.value = res.data.idsStr;
			}
		}).then(() => {
			params.departIds = departIds.value;
			if (props.groupId != "") {
				params.groupId = props.groupId;
				delete params.departIds
			}
			http.post(props.url, params).then((res) => {
				if (res && res.data && res.data.code == 1) {
					total.value = res.data.total;
					tableData.splice(0, tableData.length);
					res.data.rows.forEach((item) => {
						tableData.push(item)
					});
					doMap();
				}
			}).catch((re) => {
				console.log(re);
			});
		}).catch((re) => {
			console.log(re);
		});
	}
	//转换周
	function changeDay(type) {
		//改变日期列表
		let tempDate = null //当前时间对象
		if (type == "nowDay") {
			//当前周
			tempDate = new Date();
		} else if (type == "preDay") {
			tempDate = parseDate(lookDay.value, "yyyy-MM-dd");
			//当前周
			//检查当前日期范围是否合适1
			tempDate = tempDate.setDate(tempDate.getDate() - 1); //指定日期减1天
			tempDate = new Date(tempDate);
		} else if (type == "nextDay") {
			tempDate = parseDate(lookDay.value, "yyyy-MM-dd");
			//当前周
			//检查当前日期范围是否合适1
			tempDate = tempDate.setDate(tempDate.getDate() + 1); //指定日期减2天
			tempDate = new Date(tempDate);
		}
		lookDay.value = formatDate(tempDate, "yyyy-MM-dd");
		findData()
	}
	//把数据放到map中
	function doMap() {
		tmap.clear();
		tableData.forEach((item, index) => {
			item.personalPlanList.forEach((item2) => {
				tmap.set(item.id + "_" + lookDay.value + "_" + item2.startTime + "-" + item2.endTime,
					item2);
			})
		})
	}
	/**
	 * @param {Object} obj 人对象
	 * @param {Object} item 时间块
	 * @param {Object} type 
	 */
	function getItemForClass(obj, item, type) {
		let nn = tmap.get(obj.id + "_" + lookDay.value + "_" + item.startTime + "-" + item.endTime);
		if (nn && nn.creatorId == "2" && pinia.userId != "2") {
			return "abj"
		}
		if (type != "c") {
			if (nn) {
				return "bj" + nn.type;
			} else {
				return "bj";
			}
		} else {
			if (nn) {
				return "nbj" + nn.type;
			} else {
				return "nbj";
			}
		}
	}
	//得到选择框名
	function getCheckBoxName(obj, item) {
		return obj.id + "_" + lookDay.value + "_" + item.startTime + "-" + item.endTime;
	}
	//得到cell的值
	function getItem(obj, item) {
		return tmap.get(obj.id + "_" + lookDay.value + "_" + item.startTime + "-" + item.endTime)
	}
	//多选框变化
	function checkboxChange(e) {
		clickItems.splice(0, clickItems.length);
		clickItems.push(e.detail.value.pop());
		if (clickItems.length == 1) {
			fab.content = fab.contentsingle
			setTimeout(() => {
				myfab.value.open();
			}, 1000)
		}
		console.log(e, clickItems)
	}
	//得到按钮的类型
	function getButtonType(t, item, t2) {
		if (t.includes(item.startTime + '-' + item.endTime) && t[0] == (item.startTime + '-' + item.endTime)) {
			return "primary";
		} else if (t.includes(item.startTime + '-' + item.endTime)) {
			return "warn"
		} else if (t2.includes(item.startTime + '-' + item.endTime)) {
			return "primary"
		} else {
			return "default"
		}
	}
	//类型radio点击
	function radioTypeChange(e) {
		projectShow.value = false;
		ywShow.value = false;
		typeDefault.value = e;
		if (e == 1) {
			projectShow.value = true;
		}
		if (e == 5) {
			ywShow.value = true;
		}
	}
	//类型radio project点击
	function radioTypeChangeProject(e) {
		inputTitleText.value = e;
	}
	//类型radio updown点击
	function radioTypeChangeUpdown(e) {
		dispAddrList.splice(0, dispAddrList.length);
		if (e == 3) {
			addrList.forEach((item) => {
				dispAddrList.push(item);
			});
		} else {
			let t = addrList.filter(item => item.updown == e)
			t.forEach((item) => {
				dispAddrList.push(item);
			})
		}
	}
	//类型radio yw点击
	function radioTypeChangeYwlist(e) {
		inputTitleText.value = e.split("_")[1];
	}
	//点击删除标签
	function deleteTag(item, deleteType) {
		console.log(deleteType)
		utils.showConfirm("确认要删除吗?", function() {
			http.post("/tag/delete", {
				id: item.id
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					http.post("/tag/query", {
						type: deleteType
					}).then((res) => {
						if (res && res.data && res.data.code == 1) {
							if ("personal-title" == deleteType) {
								titleTags.splice(0, titleTags.length);
							} else if ("personal-content" == deleteType) {
								contentTags.splice(0, contentTags.length);
							}
							res.data.data.forEach((item) => {
								if ("personal-title" == deleteType) {
									titleTags.push(item);
								} else if ("personal-content" == deleteType) {
									contentTags.push(item);
								}
							});
						} else {
							myuToast.value.show({
								type: "error",
								message: res.data.msg
							})
						}
					}).catch((re) => {
						console.log(re);
					});
				}
			}).catch((re) => {
				console.log(re);
			});
		})

	}
	//点击加入标签
	function addTag(type) {
		console.log(type)
		let text = ""
		if (type == "personal-title") {
			text = inputTitleText.value;
		} else if (type == "personal-content") {
			text = inputContentText.value;
		}
		if (text == "" || !text) {
			myuToast.value.show({
				type: "error",
				message: "标签名不能为空"
			});
			return;
		}
		http.post("/tag/add", {
			type: type,
			name: text,
			color: clickColor.value
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				http.post("/tag/query", {
					type: type
				}).then((res) => {
					if (res && res.data && res.data.code == 1) {
						if ("personal-title" == type) {
							titleTags.splice(0, titleTags.length);
						} else if ("personal-content" == type) {
							contentTags.splice(0, contentTags.length);
						}
						res.data.data.forEach((item) => {
							if ("personal-title" == type) {
								titleTags.push(item);
							} else if ("personal-content" == type) {
								contentTags.push(item);
							}
						});
					} else {
						myuToast.value.show({
							type: "error",
							message: res.data.msg
						})
					}
				}).catch((re) => {
					console.log(re);
				});
			} else {
				console.log(myuToast.value)
				myuToast.value.show({
					type: 'error',
					message: res.data.msg
				})
			}
		}).catch((re) => {
			console.log(re);
		});
	}
	//日期点击
	function dayClick(item) {
		if (selectDayList.includes(item.workDate)) {
			var index = selectDayList.indexOf(item.workDate);
			selectDayList.splice(index, 1);
		} else {
			selectDayList.push(item.workDate);
		}
	}
	//日期点击
	function timeClick(item) {
		if (selectTimeList.includes(item.startTime + "-" + item.endTime)) {
			var index = selectTimeList.indexOf(item.startTime + "-" + item.endTime);
			selectTimeList.splice(index, 1);
		} else {
			selectTimeList.push(item.startTime + "-" + item.endTime);
		}
		console.log(item)
	}
	//业务输入框
	function searchYw() {
		dispAddrList.splice(0, dispAddrList.length);
		if (inputSearchYw.value == "") {
			addrList.forEach((item) => {
				dispAddrList.push(item);
			})
		} else {
			addrList.forEach((item) => {
				if (item.name.indexOf(inputSearchYw.value) != -1) {
					dispAddrList.push(item);
				}
			})
		}
	}

	function switchChange() {
		console.log(ywShow.value)
		ywShow.value = !ywShow.value;
	}
	//点击标签
	function clickTag(t, type) {
		if (type == 'title') {
			inputTitleText.value = t;
		} else if (type == 'content') {
			inputContentText.value = t;
		}
	}

	function triggerfab(e) {
		console.log(e)
		fab.content[e.index].active = !e.item.active
		let text = fab.content[e.index].text;
		if (text == '完成') {
			let ids = [];
			clickItems.forEach((n) => {
				let v = n.split("_");
				let userId = v[0];
				let o = {
					id: userId
				}
				let vv = v[2];
				let i = {
					startTime: vv.split("-")[0],
					endTime: vv.split("-")[1]
				}
				let id = getItem(o, i);
				ids.push(id.id);
			});
			http.post("/personalPlan/stateChange", {
				id: ids.join(","),
				state: 1
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		} else if (text == '取消完成') {
			let ids = [];
			clickItems.forEach((n) => {
				let v = n.split("_");
				let userId = v[0];
				let o = {
					id: userId
				}
				let vv = v[2];
				let i = {
					startTime: vv.split("-")[0],
					endTime: vv.split("-")[1]
				}
				let id = getItem(o, i);
				ids.push(id.id);
			});
			http.post("/personalPlan/stateChange", {
				id: ids.join(","),
				state: 0
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		} else if (text == '删除') {
			let ids = [];
			clickItems.forEach((n) => {
				let v = n.split("_");
				let userId = v[0];
				let o = {
					id: userId
				}
				let vv = v[2];
				let i = {
					startTime: vv.split("-")[0],
					endTime: vv.split("-")[1]
				}
				let id = getItem(o, i);
				ids.push(id.id);
			});
			http.post("/personalPlan/deleByPlanIds", {
				planIds: ids.join(",")
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		} else if (text == '全天删除') {
			let userId = ""
			clickItems.forEach((n) => {
				let v = n.split("_");
				userId = v[0];
			});
			http.post("/personalPlan/deleAllDay", {
				workDate: lookDay.value,
				userId: userId
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		}
	}

	//计划保存
	function planSave() {
		if (inputTitleText.value == "") {
			myuToast.value.show({
				"type": "error",
				message: "标题不能为空！"
			})
			return;
		}
		if (inputContentText.value == "") {
			myuToast.value.show({
				"type": "error",
				message: "内容不能为空！"
			})
			return;
		}
		let d = {};
		if (!isEdit.value) {
			d.type = typeDefault.value;
			d.title = inputTitleText.value;
			d.content = inputContentText.value;
			todayUseTime.forEach((item) => {
				selectTimeList.push(item);
			})
			selectDayList.push(lookDay.value);
			d.selectTimeList = selectTimeList.join(",");
			d.selectDayList = selectDayList.join(",");
			d.userId = clickUserId.value;
			//新增
			http.post("/personalPlan/edit", d).then((res) => {
				if (res && res.data && res.data.code == 1) {
					myuToast.value.show({
						type: "success",
						message: "保存成功"
					});
					clickItems.splice(0, clickItems.length)
					popup.value.close();
					findData();
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re)
			});
		} else {
			//单个编辑
			if (clickItems.length == 1 || clickItems.length == 0) {
				d = editobj;
				delete d.creator;
				console.log(d, "------------------")
				d.type = typeDefault.value;
				d.title = inputTitleText.value;
				d.content = inputContentText.value;

				http.post("/personalPlan/edit", d).then((res) => {
					if (res && res.data && res.data.code == 1) {
						myuToast.value.show({
							type: "success",
							message: "保存成功"
						});
						clickItems.splice(0, clickItems.length)
						popup.value.close();
						findData();
					} else {
						myuToast.value.show({
							type: "error",
							message: res.data.msg
						})
					}
				}).catch((re) => {
					console.log(re)
				});
			}
		}
	}
	//计划取消
	function planClose() {
		popup.value.close();
	}
	//选择器定了确认
	function confirmColor(e) {
		clickColor.value = e.hex;
		console.log(e, clickColor)
	}

	function confirmDate(e) {
		lookDay.value = formatDate(new Date(e.value), "yyyy-MM-dd");
		showCalendar.value = false;
		findData()
	}

	function cancelDate() {
		showCalendar.value = false;
	}
	//翻页
	function doChangePage(e) {
		console.log(e)
		params.page = e.current;
		findData()
	}
	//跳到个人计划页面
	function goPersonalPlan(obj, item, index) {
		uni.navigateTo({
			url: "/pages/all-plan/show-personal-plan",
			success: (res) => {
				uni.$emit("allplansend", obj, item, index + ((params.page - 1) * params.size));
			}
		});
	}
	//打开色
	function openColorPick() {
		colorPicker.value.open();
	}
	//关闭
	function colseColorPick() {
		colorPicker.value.close();
	}
</script>

<style scoped>
	@import '@/static/css/item.css';

	.my-scroll-view-H {
		white-space: nowrap;
		width: calc(100% - 280rpx);
		background-color: #FFFFFF;
	}
</style>